package com.neusoft.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.neusoft.bean.AdminInfoBean;
import com.neusoft.bean.AdminInfoBeanDTO;
import com.neusoft.myutils.MyUtil;
import com.neusoft.service.AdminInfoService;

@WebServlet("/AdminInfoAjaxQueryServlet")
public class AdminInfoAjaxQueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取form表单数据
		AdminInfoBeanDTO adminB = MyUtil.convertRequestParameters2Bean(request, AdminInfoBeanDTO.class);
		// 调用service方法进行数据库查询操作
		List<AdminInfoBean> lstAdmins = MyUtil.getNewInstance(AdminInfoService.class).getAdminInfoByParas(adminB);
		// 将结果集转换为json字符串
		String strJsonListAdmins = JSON.toJSONStringWithDateFormat(lstAdmins, "yyyy-MM-dd HH:mm:ss");
		System.out.println("Json:"+strJsonListAdmins);
		// 在跳转页面之前，将查询结果使用response的writer对象将影响内容写出到客户端（类似于socket通信时的响应）
		PrintWriter pw = response.getWriter();
		pw.write(strJsonListAdmins);
		// 清空
		pw.flush();
		// 关闭资源
		pw.close();
	}

}
